
angular.module('QualityJudge')

.controller('QualityJudge.DetailCtrl', ['$scope', '$ionicHistory', 'QualityJudgeMaster', 'imanDialog', 'QualityJudgeHttpUtil', 
    function ($scope, $ionicHistory, QualityJudgeMaster, imanDialog, QualityJudgeHttpUtil) {
        $scope.data = {
            badDetail: {},
            description: ''
        };

        $scope.doJudge = function (qcStatus) {
            var barcode = QualityJudgeMaster.getActiveMasterCode();
            QualityJudgeHttpUtil.doJudge(barcode, qcStatus).then(function () {
                imanDialog.toastCenter('品质判定成功');
                if ($ionicHistory.backView()) {
                    $ionicHistory.goBack();
                }
            });
        };

        $scope.$on('$ionicView.afterEnter', function () {
            QualityJudgeMaster.getActiveMaster().then(function (detail) {
                $scope.data.badDetail = detail;
            });
        });
        $scope.$on('$ionicView.beforeLeave', function () {
            QualityJudgeMaster.setActiveMaster(null);
            QualityJudgeMaster.setActiveMasterCode(null);
        });
    }
]);